home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / slock / lock.dpr < prev    next >
Text File  |  1998-09-24  |  5KB  |  123 lines

  1. library Lock;
  2.  
  3. uses
  4.   SysUtils,
  5.   Classes,
  6.   SLokUtil;
  7.  
  8. type TBufRec = record
  9.      Address: Integer;
  10.      Header:  array[0..3] of Byte;
  11.      Buffer:  TBuffer;
  12. end;
  13.  
  14. {*******************************************************************************
  15. * Variable  : Buffer                                                           *
  16. ********************************************************************************
  17. * Purpose   : This is the buffer which stores the registration information.    *
  18. *             The registration information is written into the buffer by SLock *
  19. *             and should you want to extend this DLL to also perform other     *
  20. *             tasks, you should bear in mind that you cannot link this DLL     *
  21. *             permanently, or you will inhibit the writing of the file.        *
  22. ********************************************************************************
  23. * Paramters : None                                                             *
  24. ********************************************************************************
  25. * Returns   : None                                                             *
  26. *******************************************************************************}
  27. const
  28.      Bufrec: TBufrec = (Header : (Ord('B'),Ord('u'),Ord('f'),Ord(':')));
  29.  
  30. {*******************************************************************************
  31. * Procedure : GetRegInfo                                                       *
  32. ********************************************************************************
  33. * Purpose   : GetRegInfo simply returns the contents of the buffer to the      *
  34. *             calling program.                                                 *
  35. ********************************************************************************
  36. * Paramters : None                                                             *
  37. ********************************************************************************
  38. * Returns   : Buffer: The registration information                             *
  39. *******************************************************************************}
  40. function GetRegInfo: TBuffer; stdcall;
  41. begin
  42.      Result := Bufrec.Buffer;
  43. end; {GetRegInfo}
  44.  
  45. {*******************************************************************************
  46. * Procedure : GetBuffAddr                                                      *
  47. ********************************************************************************
  48. * Purpose   : GetBuffAddr returns the offset of the buffer in the DLL to allow *
  49. *             SLock to access the buffer. If you change the DLL to add other   *
  50. *             functions, you should change the value returned by this function *
  51. *             to point to the right place. NOTE that the DLL must be dynamic-  *
  52. *             ally linked to the main program or SLock will not be able to     *
  53. *             gain write access to the file.                                   *
  54. *                                                                              *
  55. *             NOTE: The value returned by this can be optimised so that there  *
  56. *             is no need to search for the start of the buffer, rather it can  *
  57. *             returned directly.                                               *
  58. ********************************************************************************
  59. * Paramters : None                                                             *
  60. ********************************************************************************
  61. * Returns   : BufferAddress: The address of the buffer                         *
  62. *******************************************************************************}
  63. function GetBuffAddr(dllName: Pchar): integer; stdcall;
  64. var
  65.      OutputFile: File of Byte;
  66.      b,c,d: Byte;
  67.      Counter: integer;
  68. begin
  69.      try
  70.           AssignFile(OutputFile, dllName);
  71.      except
  72.           // we could not open the output file for some reason
  73.           // so exit gracefully with an error code
  74.           Result := 0;
  75.           CloseFile(OutputFile);
  76.           Exit;
  77.      end;
  78.  
  79.      // reset the output file
  80.      FileMode := 0;
  81.      Reset(OutputFile);
  82.  
  83.      // get past the most of the overhead
  84.      // ** this should be optimised to make the access fast
  85.      // if you change the DLL!! **
  86.      // You can use the DLLTest project to find out the start of
  87.      // the buffer and hard code this value into the function.
  88.      Seek(OutputFile,46670);
  89.      Counter := 46669;
  90.  
  91.      // locate the right place in the file
  92.      while not EOF(OutputFile) do
  93.      begin
  94.           Inc(Counter);
  95.           Read(OutputFile,b);
  96.           if b = Ord('B') then
  97.           begin
  98.                Read(OutputFile,b,c,d);
  99.                if ((b = Ord('u')) and (c = Ord('f')) and (d = ORD(':'))) then
  100.                begin
  101.                     // display the offset of the buffer from file start
  102.                     Result := Counter + 4;
  103.                     CloseFile(OutputFile);
  104.                     Exit;
  105.                end
  106.                else
  107.                begin
  108.                     Inc(Counter,3);
  109.                end;
  110.           end;
  111.      end;
  112.  
  113.      Result := 0;
  114.      CloseFile(OutputFile);
  115. end; {GetBufferAddress}
  116.  
  117. exports
  118.      GetRegInfo  index 1,
  119.      GetBuffAddr index 2;
  120.  
  121. end.
  122.  
  123.